var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "react", "controls/design-view", "services/page-datas", "services/local-service", "components/product-info/component", "services/shopping", "services/dataSources"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    const React = require("react");
    const design_view_1 = require("controls/design-view");
    const page_datas_1 = require("services/page-datas");
    const local_service_1 = require("services/local-service");
    const component_1 = require("components/product-info/component");
    const shopping_1 = require("services/shopping");
    const dataSources_1 = require("services/dataSources");
    class ProductPage extends React.Component {
        constructor(props) {
            super(props);
            this.localService = this.props.createService(local_service_1.LocalService);
            this.shoppingService = this.props.createService(shopping_1.ShoppingService);
            let pageData = page_datas_1.defaultPageDatas.product();
            this.pageDataReocrd = { pageData, name: "product" };
        }
        componentDidMount() {
            let designViewSave = this.designView.save;
            this.designView.save = () => __awaiter(this, void 0, void 0, function* () {
                console.assert(this.designView.designer.value != null);
                this.designView.designer.value.allComponents().filter(o => o.props != null);
                let c = this.designView.designer.value.findComponetsByTypeName(component_1.ProductInfo.name)[0];
                console.assert(c != null);
                yield dataSources_1.dataSources.product.insert(c.props.product);
                console.assert(c.props.product.Id != null);
                this.pageDataReocrd.id = c.props.product.Id;
                return designViewSave.apply(this.designView);
            });
        }
        render() {
            return React.createElement(design_view_1.DesignView, Object.assign({}, { app: this.props.app }, { pageDataRecord: this.pageDataReocrd, hidePageSettingPanel: true, ref: e => this.designView = this.designView || e }));
        }
    }
    exports.default = ProductPage;
});
